<?php
$root = dirname(__FILE__).'/';

$dir_iterator = new RecursiveDirectoryIterator($root.'collections');
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);

foreach ($iterator as $file)
{
  $filename = $file->getFilename();
  if ($file->isDir())
  {
    $image_iterator = new RecursiveDirectoryIterator($file);
    foreach ($image_iterator as $image)
    {
      if ($image->isFile())
      {
          if(strpos($image, '_low.jpeg'))
          {
            unlink($image);
          }
          else if(strpos($image, '_high.jpeg'))
          {
            rename($image, preg_replace('/_high/', '', $image));
          }
      }
    }
  }
}
?>

